package com.webchat.pgc.controller;

import com.webchat.common.bean.APIPageResponseBean;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.domain.vo.request.publicaccount.SaveArticleRequestVO;
import com.webchat.domain.vo.response.publicaccount.ArticleBaseResponseVO;
import com.webchat.pgc.service.OfficialArticleService;
import com.webchat.rmi.pgc.OfficialArticleClient;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class OfficialArticleController implements OfficialArticleClient {


    @Autowired
    private OfficialArticleService officialArticleService;

    @Override
    public APIResponseBean<Long> submit(@RequestBody SaveArticleRequestVO saveArticleRequest) {

        return APIResponseBeanUtil.success(officialArticleService.submit(saveArticleRequest));
    }

    @Override
    public APIResponseBean<ArticleBaseResponseVO> detail(Long id, Boolean isNeedContent) {

        ArticleBaseResponseVO articleVo =
                officialArticleService.getArticleDetailFromCache(id, ObjectUtils.equals(isNeedContent, true));
        return APIResponseBeanUtil.success(articleVo);
    }

    @Override
    public APIResponseBean<APIPageResponseBean<ArticleBaseResponseVO>> page(Integer pageNo, Integer pageSize) {

        return APIResponseBeanUtil.success(officialArticleService.page(pageNo, pageSize));
    }

    @Override
    public APIResponseBean<Map<Long, ArticleBaseResponseVO>> batchGet(@RequestBody List<Long> articleIds) {

        return APIResponseBeanUtil.success(officialArticleService.batchGetArticleDetailFromCache(articleIds));
    }
}
